<?php
/**
 * 用户导出
 * author itholiday@126.com
 */
if (isset($_GET['ids']) && !empty($_GET['ids'])) {
    $ids = addslashes($_GET['ids']);
    $where = "u.id in ($ids) ";
}else{
    $where = 'u.id>0 ';
}

$keyword = isset($_GPC['keyword']) && !empty($_GPC['keyword']) ? input('keyword') : '';
$start_time = isset($_GPC['start_time']) && !empty($_GPC['start_time']) ? strtotime($_GPC['start_time']) : '';
$end_time = isset($_GPC['end_time']) && !empty($_GPC['end_time']) ? strtotime($_GPC['end_time']) : '';

if (!empty($keyword)){
    $where .= " and (u.mobile='$keyword'  or u.truename like '%$keyword%') ";
}

if (!empty($start_time) && !empty($end_time)) {
    $where .= " and u.create_time>=$start_time and u.create_time<=$end_time ";
} else {
    if (!empty($start_time)) {
        $where .= " and u.create_time>=$start_time ";
    }
    if (!empty($end_time)) {
        $where .= " and u.create_time<=$start_time ";
    }
}

$field = 'u.id,u.mobile,u.truename,u.user_money,u.alipay_name,u.alipay_account,u.last_login_ip,u.user_status';
$sql = "select $field from ims_yq_haircircle_users u order by u.id";

$data = pdo_fetchall($sql);


if(empty($data)) $data = array();

foreach ($data as $k => $v) {
    if ($v['user_status'] == 0) {
        $data[$k]['user_status'] = '禁用';
    } elseif ($v['user_status'] == 1) {
        $data[$k]['user_status'] = '正常';
    } elseif ($v['user_status'] == 2) {
        $data[$k]['user_status'] = '未验证';
    } else {
        $data[$k]['user_status'] = '待审核';
    }
}

$data['user_money'] = sprintf("%.2f", $data['user_money']);
$fileName = '会员列表_' . date('YmdHis');
$header = array(
    '用户ID', '手机号', '真实姓名', '账户余额', '支付宝姓名', '支付宝账号','上次登录IP','状态'
);

exportExcel($data, $fileName,$header , '会员列表');